package com.beiding.jsonanalyzer.analyze.func.openfunc;

import com.beiding.jsonanalyzer.analyze.func.FuncFactory;
import com.beiding.jsonanalyzer.analyze.func.base.EasyAggFunc;
import com.beiding.jsonanalyzer.analyze.func.base.FuncFactoryAdaptor;

import java.util.List;

/**
 * 桶,返回该分支所有结果
 *
 * @author 丁常磊
 * @date 2022/5/10 15:39
 */

public class Bucket{

    public static FuncFactory of(Object exp, boolean distinct) {
        return FuncUtils.buildForEasyAgg(new FuncFactoryAdaptor<EasyAggFunc>() {
            @Override
            protected EasyAggFunc newInstance() {
                return new EasyAggFunc() {
                    @Override
                    public Object agg(List<Object> list) {
                        return list;
                    }
                    @Override
                    public String toString() {
                        if (distinct) {
                            return "bucket(distinct" + core + ")";
                        } else {
                            return "bucket(" + core + ")";
                        }
                    }
                };

            }
        }, exp, distinct);
    }

    public static FuncFactory of(Object exp) {
        return of(exp, false);
    }



}